<template>
	<el-container>
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="搜索工序任务单号/产品名称" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
				<div class="left-panel"></div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :data="data" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column fixed="left" type="selection" width="50" reserve-selection></el-table-column>
					<el-table-column label="操作" fixed="left" align="center" width="170">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_work(scope.row, scope.$index)">开工</el-button>
								<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">停工</el-button>
								<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">报工</el-button>
							</el-button-group>
						</template>
					</el-table-column>
					<el-table-column label="工序任务单号" prop="customAddress"></el-table-column>
					<el-table-column label="工序计划单号" prop="customAddress"></el-table-column>
					<el-table-column label="产品编码" prop="name"></el-table-column>
					<el-table-column label="产品名称" prop="customAddress"></el-table-column>
					<el-table-column label="工序名称" prop="customAddress"></el-table-column>
					<el-table-column label="工序状态" prop="customAddress"></el-table-column>
					<el-table-column label="是否委外" prop="customAddress"></el-table-column>
					<el-table-column label="报工权限" prop="customAddress"></el-table-column>
					<el-table-column label="工艺文件" prop="customAddress"></el-table-column>
					<el-table-column label="工艺路线" prop="customAddress"></el-table-column>
					<el-table-column label="生产车间" prop="customAddress"></el-table-column>
					<el-table-column label="产品编码" prop="customAddress"></el-table-column>
					<el-table-column label="产品名称" prop="customAddress"></el-table-column>
					<el-table-column label="产品类别" prop="customAddress"></el-table-column>
					<el-table-column label="规格型号" prop="customAddress"></el-table-column>
					<el-table-column label="计划开工日期" prop="customAddress"></el-table-column>
					<el-table-column label="计划完工日期" prop="customAddress"></el-table-column>
					<el-table-column label="单位" prop="customAddress"></el-table-column>
					<el-table-column label="数量" prop="customAddress"></el-table-column>
					<el-table-column label="工序计划单号" prop="customAddress"></el-table-column>
					<el-table-column label="顺序号" prop="customAddress"></el-table-column>
					<el-table-column label="工序名称" prop="customAddress"></el-table-column>
					<el-table-column label="产出比例" prop="customAddress"></el-table-column>
					<el-table-column label="前置工序顺序号" prop="customAddress"></el-table-column>
					<el-table-column label="加工说明" prop="customAddress"></el-table-column>
					<el-table-column label="车间名称" prop="customAddress"></el-table-column>
					<el-table-column label="操作工" prop="customAddress"></el-table-column>
					<el-table-column label="时间单位" prop="customAddress"></el-table-column>
					<el-table-column label="标准工时" prop="customAddress"></el-table-column>
					<el-table-column label="标准总工时" prop="customAddress"></el-table-column>
					<el-table-column label="工序计划数量" prop="customAddress"></el-table-column>
					<el-table-column label="良品数" prop="customAddress"></el-table-column>
					<el-table-column label="不良品数" prop="customAddress"></el-table-column>
					<el-table-column label="返修数" prop="customAddress"></el-table-column>
					<el-table-column label="是否末道工序" prop="customAddress"></el-table-column>
					<el-table-column label="是否检验" prop="customAddress"></el-table-column>
					<el-table-column label="变更次数" prop="customAddress"></el-table-column>
					<el-table-column label="单位计时工资" prop="customAddress"></el-table-column>
					<el-table-column label="单位计件工资" prop="customAddress"></el-table-column>
					<el-table-column label="工序计划开工时间" prop="customAddress"></el-table-column>
					<el-table-column label="工序计划完工时间" prop="customAddress"></el-table-column>
					<el-table-column label="行完工状态" prop="customAddress"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
export default {
	name: 'user',
	components: {},
	data() {
		return {
			dialog: {
				details: false,
			},
			group: [],
			apiObj: this.$API.basicdata.applyList.getList,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
			menuList: [],
			menuProps: {
				label: (data) => {
					return data.cate_name
				}
			},
			menuloading: false,
			menuFilterText: "",
			menuForm: {},
			data: [
				{
					name: '张三',
				},
				{
					name: '李四',
					age: 20,
				},
				{
					name: '李四',
					age: 20,
				},
				{
					name: '李四',
					age: 20,
				},
			],
		}
	},
	watch: {
		menuFilterText(val) {
			this.$refs.menu.filter(val);
		}
	},
	mounted() {
		this.getMenu();
	},
	methods: {
		/**查看点击*/
		batch_show() {
			this.dialog.details = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open('add')
			})
		},
		//加载树数据
		async getMenu() {
			this.menuloading = true;
			var res = await this.$API.all.getBeiCate.get();
			this.menuloading = false;
			var allNode = {id: '', cate_name: '所有'}
			res.data.unshift(allNode);
			this.menuList = res.data;
			this.menuClick(allNode)
		},
		//树点击
		menuClick(data) {
			this.menuForm = data
			var params = {
				cate_id: data.id,
			}
			this.$refs.table.reload(params)
		},
		//树过滤
		menuFilterNode(value, data) {
			if (!value) return true;
			return data.cate_name.indexOf(value) !== -1;
		},
		/**删除菜单*/
		async delMenu() {
			if (!this.menuForm.id) {
				this.$message.warning("请选择需要删除的项")
				return false;
			}
			var confirm = await this.$confirm('确认删除已选择的分类吗？', '提示', {
				type: 'warning',
				confirmButtonText: '删除',
				confirmButtonClass: 'el-button--danger'
			}).catch(() => {
			})
			if (confirm != 'confirm') {
				return false
			}
			this.menuloading = true
			var reqData = {
				id: this.menuForm.id
			}
			var res = await this.$API.answers.cate.delete.post(reqData)
			this.menuloading = false
			if (res.code == 1) {
				this.getMenu()
				this.menuForm = {}
			} else {
				this.$message.warning(res.message)
			}
		},
		/**添加分类*/
		addType() {
			this.dialog.cate = true
			this.$nextTick(() => {
				this.$refs.cateDialog.open('add')
			})
		},
		/**编辑分类*/
		editMenu() {
			if (!this.menuForm.id) {
				this.$message.warning("请选择需要编辑的项")
				return false;
			}
			this.dialog.cate = true
			this.$nextTick(() => {
				this.$refs.cateDialog.open('edit').setData(this.menuForm)
			})
		},
		/**分类添加成功事件*/
		cateHandleSuccess() {
			this.getMenu();
		},
		//添加
		add() {
			this.$router.push({
				path: '/testing/addOption',
			});
		},
		//编辑
		table_edit(row) {
			let form = row
			form.zhuangtai = 'edit'
			this.$router.push({
				path: '/testing/addOption',
				query: form
			});
		},
		/**双击事件*/
		dblclick(row) {
			this.table_show(row)
		},
		//查看
		table_show(row) {
			let form = row
			form.zhuangtai = 'show'
			this.$router.push({
				path: '/testing/addOption',
				query: form
			});
		},
		//表格内开关
		async changeSwitch(val, row) {
			row.$switch_status = true;
			var res = await this.$API.basicdata.applyList.update_status.post({
				id: row.id,
				system_disable: row.system_disable,
			});
			if (res.code == 1) {
				row.$switch_status = false;
				this.$refs.table.refresh();
				this.$message.success("操作成功");
			} else {
				this.$alert(res.message, "提示", {type: "error"});
			}
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.basicdata.applyList.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
			this.printArr = ''
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
